package com.culturalCenter.dataCenter.service.impl.monitor;

import cn.hutool.core.date.DateUtil;
import com.culturalCenter.dataCenter.customEntity.monitor.CustomMeteotograph;
import com.culturalCenter.dataCenter.customEntity.responseParam.monitor.MeteotographResponse;
import com.culturalCenter.dataCenter.customEntity.responseParam.monitor.TemperatureResponse;
import com.culturalCenter.dataCenter.mapper.monitor.MeteotographMapper;
import com.culturalCenter.dataCenter.service.monitor.MeteotographService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

/**
 * @author 方治森
 * @since 2022/2/28
 */
@Service
public class MeteotographServiceImpl implements MeteotographService {

    @Resource
    private MeteotographMapper meteotographMapper;

    @Override
    public MeteotographResponse getAll() {
        MeteotographResponse meteotographResponse = meteotographMapper.getLatest();
        List<CustomMeteotograph> list = meteotographMapper.getList();
        list.forEach(item -> {
            if (DateUtil.formatDate(item.getDate()).equals(DateUtil.formatDate(DateUtil.yesterday()))) {
                item.setDayOfWeek("昨天");
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("EEEE", Locale.CHINA);
                item.setDayOfWeek(sdf.format(item.getDate()));
            }
        });
        meteotographResponse.setHistoryRecord(list);
        return meteotographResponse;
    }

    @Override
    public TemperatureResponse getTemperature() {
        return meteotographMapper.getTemperature();
    }

}
